<!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-03-07 13:36:39
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2024-01-19 16:12:18
 * @FilePath: \newMould_BHZ\src\views\WaterManage\trends\instantly.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 水稳----动态监控---实时监控 -->
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav app-container-search">
        <!-- 左侧 -->
        <el-form ref="form" :model="getList" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="6"
              ><el-form-item label="项目名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fprojectid"
                  placeholder="所有项目"
                  @change="selectProject"
                >
                  <el-option
                    v-for="v in projectsObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="标段名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fCompanyid"
                  placeholder="所有标段"
                  @change="selectTender"
                >
                  <el-option
                    v-for="v in tendersObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="梁场名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.stationId"
                  placeholder="梁场查询"
                  @change="selectStation"
                >
                  <el-option
                    v-for="v in bhzDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="张拉机名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.machineId"
                  placeholder="张拉机查询"
                >
                  <el-option
                    v-for="v in bhjDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="张拉日期：">
                <el-date-picker
                  :picker-options="pickerOptions"
                  value-format="yyyy-MM-dd"
                  @change="selectTime"
                  v-model="timeDuring"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :append-to-body="false"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item label="开始日期">
                <el-date-picker v-model="getList.startDates" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束日期">
                <el-date-picker v-model="getList.endDates" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col> -->
            <el-col :span="6"
              ><el-form-item label="预警级别：">
                <el-select
                  class="selectBhz"
                  v-model="getList.warningLevel"
                  placeholder="超标查询"
                >
                  <el-option
                    v-for="v in exceedList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="分部分项：">
                <el-input
                  type="text"
                  placeholder="分部分项查询"
                  v-model="getList.keyWord"
                /> </el-form-item
            ></el-col>
          </el-row>
          <div class="searchBtn">
            <el-button
              type="primary"
              :loading="editLoading"
              @click="yj_searchForm(getList)"
              >查询</el-button
            >
            <el-button @click="reset">重置</el-button>
          </div>
        </el-form>
      </div>

      <div class="app-container-btn">
        <el-button type="primary" @click="yj_viewForm">查看</el-button>
      </div>
      <!-- 表格 -->
      <div class="text_table TensionRealTime">
        <tableData
          :page="getList.page"
          :pageSize="getList.pageSize"
          :stripe="false"
          height="100%"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
        />

        <pagination
          :info="queryCriteriaDatas"
          :total="queryCriteriaDatas.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
    </div>
    <messageBox
      :showMsgBox="showMsgBox"
      :msgTip="msgTip"
      :msgType="msgType"
      @confirmMsg="confirmMsg"
    ></messageBox>
  </div>
</template>

<script>
import messageBox from "@/components/public/messageBox"; //弹框

import actions from "@/actions";
// import tree from "@/components/TensionAndGrout/tree";
import TableData from "@/components/waterManage/public/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
// import PaginationS from "@/components/TensionAndGrout/TensionManage/TensionRealTime/el-pagination"; //弹框分页
// import pressureCharts from "@/components/TensionAndGrout/TensionManage/TensionRealTime/pressureCharts"; //油压
// import tensioningCharts from "@/components/TensionAndGrout/TensionManage/TensionRealTime/tensioningCharts"; //张拉力
// import elongationCharts from "@/components/TensionAndGrout/TensionManage/TensionRealTime/elongationCharts"; //伸长量
// import tripCharts from "@/components/TensionAndGrout/TensionManage/TensionRealTime/tripCharts"; //伸长量
import formJs from "./regexDetail.js"; //新增弹框配置项

import {
  getTensioningLists, //主页面列表接口
  getStationmachineList, //梁场设备查询
  getMachineListByStationId, //4张拉机、5压浆机设备查询
  // getGXJLBaseCompanyList,//获取标段
} from "@/api/request.js";
import { statusType2 } from "@/utils/config"; //配置项
// import { statusType } from "@/utils/config"; //配置项   初中高
export default {
  name: "TensionRealTime",
  components: {
    TableData, //主页面列表
    Pagination, //分页
    messageBox,
  },
  data() {
    return {
      name: "TensionRealTime", //按钮配置页面代号
      token: null,
      showMsgBox: false,
      msgTip: "请先选中数据行！",
      msgType: 1,

      editLoading: false,
      timeDuring: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      rowInfo: null, //当前行信息
      projectsObj: [], //项目名
      tendersObj: [],
      exceedList: formJs.exceedList, //顶部下拉框---超标查询
      closeList: formJs.closeList, //顶部下拉框---闭合查询
      bhzDataList: [], //梁场
      bhjDataList: [], //张拉机
      djDataList: formJs.djDataList, //预警级别
      navigatepageNums: null, //是否显示分页
      queryCriteriaDatas: {}, //分页
      // 列表配置项
      table_config: formJs.table_config,
      tableData: [], //列表数据列表
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        fprojectid: "",
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 梁场id
        machineId: "", // 张拉机id
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
        keyWord: "", //  模糊条件
        page: 1, // 当前页数
        pageSize: 15, // 每页显示条数
        timeStr: "",
        fProjectposition: "", //工程部位模糊查询
        taskNo: "", //任务单模糊查询
        fStatus: "", //状态
        keyType: "1", //张拉 1 压浆 2 必填
      },
      // checkData: [],
      userInfo: {}, //登录用户
      token: null,
    };
  },

  mounted() {
    actions.onGlobalStateChange((state, prev) => {
      this.userInfo = prev.currentUser;
      var data = prev.currentUser.projects;

      this.token = prev.token;
      this.projectsObj = [
        {
          fItemName: "所有项目",
          fItemValue: "",
        },
      ];
      data.map((item) => {
        this.projectsObj.push({
          fItemName: item.projectName,
          fItemValue: item.projectId,
        });
      });
    }, true);

    this.getDate();
    // this.btnRole(this.name);
    this.table_config.thead[7]["callback"] = function (rowData) {
      let data = statusType2[rowData.fWarninglevel];
      if (data) {
        return data.label;
      }
    };
    this.table_config.thead[7]["specialClass"] = function (rowData) {
      let data = statusType2[rowData.fWarninglevel];
      if (data) {
        return data.className;
      }
    };
    // this.table_config.operation.cols = [
    //   {
    //     label: "查看",
    //     type: "primary",
    //     handleRow: this.handleRow,
    //   },
    // ];
  },
  methods: {
    confirmMsg() {
      this.showMsgBox = false;
    },
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(
        sessionStorage.getItem("GxEmbedded_instantly")
      );
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },

    // 重置按钮
    reset() {
      this.timeDuring = "";
      this.getList = {
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 梁场id
        machineId: "", // 张拉机id
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
        keyWord: "", //  模糊条件
        page: 1, // 当前页数
        pageSize: 15, // 每页显示条数
        timeStr: "",
        fProjectposition: "", //工程部位模糊查询
        taskNo: "", //任务单模糊查询
        fStatus: "", //状态
        keyType: "1", ////张拉 1 压浆 2 必填
      };
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      if (this.getList.warningLevel == "==请选择==") {
        data.warningLevel = "";
      }
      if (this.getList.fCloseoperation == "==请选择==") {
        data.fCloseoperation = "";
      }
      if (this.getList.machineId == "所有张拉机") {
        data.machineId = "";
      }
      if (this.getList.stationId == "所有梁场") {
        data.stationId = "";
      }

      window.sessionStorage.setItem(
        "GxEmbedded_TensionManage_getLists",
        JSON.stringify(data)
      );
      var id;
      if (data.fCompanyid != "") {
        id = data.fCompanyid;
      } else {
        id = data.fprojectid;
      }
      var getList = {
        fCompanyid: id, // 施工标段id，不为空
        startDates: data.startDates, // 开始时间
        endDates: data.endDates, // 截至时间
        stationId: data.stationId, // 梁场id
        machineId: data.machineId, // 张拉机id
        warningLevel: data.warningLevel, // 预警等级
        fCloseoperation: data.fCloseoperation, // 闭合状态
        keyWord: data.keyWord, //  模糊条件
        page: data.page, // 当前页数
        pageSize: 15, // 每页显示条数
        fProjectposition: data.fProjectposition, //工程部位模糊查询
        taskNo: data.taskNo, //任务单模糊查询
        fStatus: data.fStatus, //状态
        keyType: "1", ////张拉 1 压浆 2 必填
      };
      getTensioningLists(getList)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaDatas = res.data.pageInfo; //分页信息
            that.navigatepageNums =
              that.queryCriteriaDatas.navigatepageNums.length;
          } else {
            this.$message.error("获取 列表数据失败", res.msg);
            this.listLoading = false;
          }
        })
        .catch((error) => {
          this.$message.error("获取列表数据 接口报错", error.msg);
          this.listLoading = false;
        });
    },
    // 查看
    yj_viewForm() {
      if (this.rowInfo != null) {
        var beamData = {
          data: this.rowInfo.fBeamid,
          fCompanyid: this.rowInfo.fCompanyid,
        };
        window.sessionStorage.setItem(
          "GxTensionManage_beam",
          JSON.stringify(beamData)
        );
        this.$router.push({
          path: "/tensionManage/tensionRealTimeFirstLevel",
          // query: {
          //   data: this.rowInfo.fBeamid,
          //   fCompanyid: this.rowInfo.fCompanyid,
          // },
        });
      } else {
        this.showMsgBox = true;
        // this.$MessageBox.alertConfirmReminder("请先选中数据行！");
      }
    },
    // 点击当前行
    rowChange(row) {
      this.rowInfo = row; //当前行信息
    },
    // 获取梁场数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "4", // 拌合站类型
      };
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            this.bhzDataList = [
              {
                fItemName: "所有梁场",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    selectProject(e) {
      this.tendersObj = [];
      this.getList.fCompanyid = "";
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhzDataList = [];
      this.bhjDataList = [];
      this.getTender(e, 1);
    },
    async getTender(e, num) {
      await this.$http(
        " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
          e,
        {
          headers: {
            "Content-Type": "application/json",
            Authorization: localStorage.getItem("access_token"),
          },
        }
      ).then((res) => {
        if (res.status == 200) {
          var data = res.data.data.GXCompanyList;
          this.tendersObj = [];
          if (data.length == 1) {
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
            this.getList.fCompanyid = data[0].sectionId;
          } else {
            this.tendersObj = [
              {
                fItemName: "所有标段",
                fItemValue: "",
              },
            ];
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
          }

          if (num == 0) {
            // num==0 调列表；num==1 不调
            this.yj_searchForm(this.getList);
          }
        }
      });
    },
    selectTender(e) {
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhzDataList = [];

      this.bhjDataList = [];

      this.mixingPlantList(0, this.getList);
    },
    selectStation(e) {
      this.getList.machineId = "";
      this.getList.stationId = e;
      this.bhjDataList = [];
      this.getbhjDataMethods(e, 4);
    },
    // 获取张拉机设备
    getbhjDataMethods(data, num) {
      getMachineListByStationId({ stationId: data, modelType: num })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有张拉机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 时间间隔
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
    },

    getDate() {
      if (
        JSON.parse(sessionStorage.getItem("GxEmbedded_TensionManage_getLists"))
      ) {
        var dataList = JSON.parse(
          sessionStorage.getItem("GxEmbedded_TensionManage_getLists")
        );
        if (dataList.fprojectid != "") {
          this.getTender(dataList.fprojectid, 0);
        } else {
          dataList.fprojectid = this.projectsObj[1].fItemValue;
          this.getTender(dataList.fprojectid, 0);
        }
        if (dataList.fCompanyid != "" && dataList.fCompanyid != null) {
          this.mixingPlantList(0, dataList);
        }

        if (dataList.stationId != "" && dataList.stationId != null) {
          this.getbhjDataMethods(dataList.stationId, 4);
        }

        // this.getList.page = 1;
        this.getList = {
          fprojectid: dataList.fprojectid,
          fCompanyid: dataList.fCompanyid, // 施工标段id，不为空
          startDates: dataList.startDates, // 开始时间
          endDates: dataList.endDates, // 截至时间
          stationId: dataList.stationId, // 梁场id
          machineId: dataList.machineId, // 张拉机id
          warningLevel: dataList.warningLevel, // 预警等级
          fCloseoperation: dataList.fCloseoperation, // 闭合状态
          keyWord: "", //  模糊条件
          page: 1, // 当前页数
          pageSize: 15, // 每页显示条数
          timeStr: dataList.timeStr,
          fProjectposition: dataList.fProjectposition, //工程部位模糊查询
          taskNo: dataList.taskNo, //任务单模糊查询
          fStatus: dataList.fStatus, //状态
          keyType: "1", ////张拉 1 压浆 2 必填
        };
        if (this.getList.startDates == "") {
          this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
          this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        }
        this.timeDuring = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fprojectid = this.projectsObj[1].fItemValue;
        this.getTender(this.getList.fprojectid, 0);
        this.timeDuring = [
          this.common.getDay(-90) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>


<style scoped lang='less'></style>


